package com.hema.auction.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.hema.auction.R;
import com.hema.auction.base.BaseActivity;
import com.hema.auction.http.HttpTag;
import com.hema.auction.http.biz.HttpManager;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * 描述:修改昵称
 * 作者:john
 */
public class EditNickNameActivity extends BaseActivity {

    @BindView(R.id.et_name)
    EditText etName;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_nick_name);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_ok})
    public void onClick(View v) {
        if (etName.getText().toString().trim().length() > 0) {
            HttpManager.getInstance(this).updateUserInfo("name", etName.getText().toString().trim(), this);
        } else {
            showToastSafe(R.string.nick_name_isempty);
        }
    }

    @Override
    protected void onSuccess(HttpTag httpTag, Call call, JSONObject result) {
        super.onSuccess(httpTag, call, result);
        switch (httpTag) {
            case TAG_UPDATE_USER_INFO:
                try {
                    if (result.getInt("errcode") == 0) {
                        profileInfo.setName(etName.getText().toString().trim());
                        updateProfile();
                        finish();
                    }
                    showToastSafe(result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
        }
    }
}
